package com.cpecc.dao.wuzi;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.cpecc.model.wuzi.BianMa;
@Repository
public class BianMaDao {

	@Resource
	private SessionFactory sessionFactory;
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	public void save(BianMa bianMa){
		Session session=sessionFactory.getCurrentSession();
		session.save(bianMa);
		session.flush();
	}
	
	public BianMa getBianMa(String wuLiaoBM){
		String hql="from BianMa t where t.wuLiaoBM=?";
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		query.setString(0, wuLiaoBM);
		if(query.list().size()>0)
			return (BianMa) query.list().get(0);
		else
			return null;
	}
	
	public boolean delete(BianMa bianMa){
		String hql="delete BianMa t where t.id=?";
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		query.setString(0, bianMa.getId());
		return query.executeUpdate()>0;
	}
}
